﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FOM.Impl;
using FOM.Interfaces;
using NUnit.Framework;

namespace TestUnits
{
     /// <summary>
    /// All tests dealing with remove
    /// </summary>
    /// <remarks>Copyright Softisis 2011 (France)</remarks>
    [TestFixture]
    public class TestRemove
    {


        [SetUp]
        public void SetUp()
        {
        }

        [Test]
        public void TestRemoveSimpleNode()
        {


            // create manager
            IManager mngr = new ManagerImpl();

            IMappingNode<ObjectA, ObjectB> rootmap = mngr.RegisterMapping<ObjectA, ObjectB>("test");
            rootmap.Map(a => a.Entier, b => b.BUnobjectC.Val1);
            rootmap.Map(a => a.Chaine, b => b.BChaine);

            // source object
            var srcA = TestObjectsHolder.GetObjectA();

            // target object
            ObjectB tofill = new ObjectB();
            tofill.BChaine = "pouet"; // must be overwritten due to mapping

            mngr.ApplyMapping("test", srcA, tofill);
            Assert.IsTrue(tofill != null);
            Assert.IsTrue(tofill.BUnobjectC != null);

            Assert.IsTrue(srcA.Entier.Equals(tofill.BUnobjectC.Val1));
            Assert.IsTrue(tofill.BChaine.Equals(tofill.BChaine));

            // we remove the 2nt map path
            rootmap.Remove(a => a.Chaine, b => b.BChaine);
            tofill.BChaine = "pouet2"; // must be overwritten due to mapping

            mngr.ApplyMapping("test", srcA, tofill);
            Assert.IsTrue(tofill != null);
            Assert.IsTrue(tofill.BUnobjectC != null);

            Assert.IsTrue(srcA.Entier.Equals(tofill.BUnobjectC.Val1));
            Assert.IsTrue(!srcA.Chaine.Equals(tofill.BChaine));

        }
    }
}
